"""
文件名: DHX_MemberCouponController.py
作用: 录入用户优惠券模块的接口
作者: 代海霞
"""
from Untils.SendMethod import SendMethod
from Untils.GetKeyword import GetKeyword
from Interface.DHX_MemberInterface import MemberInterface


class MemberCouponController:
    def __init__(self):
        self.url = 'http://139.159.146.104:8083'
        member = MemberInterface()
        self.headers = member.get_token(username='liar', password='123456')

    def get_coupon(self, couponId):
        """
        领取指定优惠券
        :param couponId: 优惠券id
        :return:
        """
        # 请求地址
        url = self.url + f'/member/coupon/add/{couponId}'
        return SendMethod.send_method(method='post', url=url, headers=self.headers)

    def get_coupon_list(self, useStatus):
        """
        获取用户优惠券列表
        :param useStatus:优惠券状态码:0-->未使用;1-->已使用;2-->已过期
        :return:
        """
        # 请求地址
        url = self.url + '/member/coupon/list'
        payload = {'userStatus': useStatus}
        return SendMethod.send_method(method='get', url=url, params=payload, headers=self.headers)

    def get_cart_coupon(self, type):
        """
        获取登录会员购物车的相关优惠券
        :param type:优惠券是否可用:0-->不可用;1-->可用
        :return:
        """
        url = self.url + f'/member/coupon/list/cart/{type}'
        return SendMethod.send_method(method='get', url=url, headers=self.headers)


if __name__ == '__main__':
    coupon = MemberCouponController()
    # print(coupon.get_coupon(couponId='2'))
    # print(coupon.get_coupon_list(useStatus=0))
    print(coupon.get_cart_coupon(type=0))